<? 
/***************************************************************************
 *                           act_xml_parser.php
 *                        ------------------------
 *   begin                : Friday, Aug 19, 2005
 *   copyright            : (C) 2005 cyber8 netWorks
 *   email                : support@cyber8.net 
 *
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/
$stack      = array();
$nodelist   = array(); 

function arrayfromxml ($url) {
    global $nodelist; 
	$nodelist = array(); 
	$req = implode ('', file ( str_replace(" ","+",$url))); 
	 
	$parser = xml_parser_create(); 
	xml_set_element_handler ($parser, "start_handler", "end_handler");
	xml_set_character_data_handler ($parser, "character_handler");
	xml_parser_set_option ($parser, XML_OPTION_CASE_FOLDING, 0);
	$bln = xml_parse ($parser, $req, 1);
	xml_parser_free ($parser);
    return $nodelist;
}


function start_handler($parser, $el_name, $attribs) { 
    global $stack; 
    global $attriblist;
    $stack[] = array ($el_name, "", $attribs);  
}
 
	
function character_handler($parser, $txt) { 
    global $stack;
    $cur = count($stack) - 1;
    $stack[$cur][1] .= $txt;
}

function end_handler($parser, $el_name) { 
    global $stack;
    global $nodelist;
    $el = array_pop($stack);	 
	$nodelist[count($nodelist)] = $el;
}

function parsefolderfromfile($path) {
	$x=implode('',file($path)); 
	parse_str($x); 
	$m=parsefolder($pvurl."?fil=".$pvroot); 
	return $m;
}

function parsefolder($url) {
	$rss=arrayfromxml($url); 
	$ret=array();
	$tmp=array(); 
	for ($e=1;$e<count($rss);$e++) {
		$node = $rss[$e]; 
		if (($node[0]=="file")||($node[0]=="folder")) {
			  $txt = $tmp["name"];
			  $tmp["title"]=$txt; 
			  $ret[$txt]=$tmp;
			  $tmp=array();  
		} else { // title
		   $val=str_replace("\\","/",$node[1]);
		   $tmp[$node[0]] = $val;  
		}
	}
	$txt=$tmp["name"];
	$tmp["title"]=$tmp["name"]; 
	$ret[$txt]=$tmp;
	 
	return $ret;
}

function parserss($url) {
	$rss=arrayfromxml($url); 
	$ret=array();
	$tmp=array();
	$bok=false;
	for ($e=1;$e<count($rss);$e++) {
		$node = $rss[$e]; 
		$atts = $node[2];
		if ($node[0]=="item") {
			  $txt = filetitle ($tmp["url"]);
			  $ret[count($ret)]=$tmp;
			  $ret[$txt]=$tmp;
			  $tmp=array(); 
		} else if ($node[0]=="enclosure") { // pubDate
		   $tmp["url"] =$atts["url"];
		   $tmp["size"]=$atts["length"];
		   $tmp["type"]=$atts["type"]; 
		} else if ($node[0]=="pubDate") $tmp["date"]=$node[1];  
		else if ($node[0]=="description") $tmp["description"]=$node[1];
		else if ($node[0]=="title") $tmp["title"] =$node[1];   
	}
	$txt = filetitle ($tmp["url"]);
	$ret[count($ret)]=$tmp;
	$ret[$txt]=$tmp;
	return $ret;
}

?>